#include "../Model/Library.h"
#include "LibraryView.h"
#include <ncurses.h>
#include <iostream>
#include <string>
#include <sstream>
#include "Settings.h"


LibraryView::LibraryView(Library & l) : lib(l) {}

Library & LibraryView::getLibrary() {
	return lib;
}

int LibraryView::showLibrary() {
	printLibrary();
	
	int ch = 0;
	int number = 0; 
	while ((ch != L_OK_KEY && ch != L_ADD_KEY && ch != L_EDIT_KEY) || number == 0) {
		ch = getch();
		if (ch <= '9' && ch >= '0') {//наверное, тут константы не нужны
			number = number*10 + (ch - 48);
		}
		if (ch == L_EXIT_KEY) return -1;
		if (ch == L_ADD_KEY) {
			//LibraryAdd
			printLibrary();
		}
	}
	
	return number - 1;
	
}


void LibraryView::printLibrary() {
	clear();
	mvprintw(0, 0, "LIBRARY: ");
	for (int i = 0; i < lib.getSize(); ++i) {
		//char n = i + '0';
		std::ostringstream os;
		os << (i + 1);
		std::string p = os.str();
		p += ".   " + lib.getRecord(i).bookName;
		
		mvprintw(i + 1,0,(p).c_str());
	}
	mvprintw(lib.getSize() + 2,0,"");
}

void LibraryView::showAddDialog() {
	clear();
	
}
